var app = getApp();
var memberUtil=require('../../utils/memberUtil');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    that.setData({
      userInfo:wx.getStorageSync('loginUserInfo').userInfo
    })
    if(that.data.userInfo.id==undefined) {
      memberUtil.getLogin(app,0,1,that,2);
    }

    var json={memberId:this.data.userInfo.id}
    wx.request({
      url: app.globalData.baseUrl+'/member/receivingAddress/findReceivingAddressByMemberId',
      header: app.globalData.headerPost,
      method: 'POST',
      data:JSON.stringify(json),
      success:function(res){
        console.log("地址调用成功"+JSON.stringify(res.data));
        if(Number(res.data.length)>0 && res.statusCode==200) {
          var items=[];
          for(var i in res.data){
            res.data[i].sub= res.data[i].receiverName.substring(0,1);
            items.push(res.data[i])
          }
          that.setData({
            address: items
          })
        }else{
          that.setData({
            address:[]
          })
        }
      }
    })
  },
  editAddress:function(e){//编辑地址
    var adId= e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/my/address?type=edit&adId='+adId
    })
  },
  add:function(){
    wx.navigateTo({
      url: '/pages/my/address?type=add'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that=this;
    return {
      title: '我的二维码',
      path: "/pages/shop/shareSuccess?parentId=" + that.data.userInfo.id + "&enterType=0",
      imageUrl: app.globalData.loginUserInfo.erweimaUrl
    }
  }
})